﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Extractor.LibCode;
using System.Windows.Forms;

namespace Extractor
{
    public partial class fSRC : Form
    {
        public string srchelp_name = "";
        public string retval = "valvalval";        
        public string retdesc = "texttexttexrt";
        
        cSearchHelp osrc;
        private DataTable dt;
        public fSRC()
        {
            InitializeComponent();
        }

        private void fSRC_Load(object sender, EventArgs e)
        {
            if (srchelp_name.Trim() == string.Empty)
            {
                throw new Exception("Undefined Search Help ID");
            }
            osrc = new cSearchHelp(srchelp_name);
            dt= new DataTable();
            osrc.getSearchHelpData(ref dt);
            gvSRC.DataSource = dt;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void gvSRC_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

            if (e.RowIndex > -1)
            {
                osrc.setReturnValue(dt, e.RowIndex, out retval, out retdesc);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }


            
        }
        
        void filter()
        {
            osrc.getSearchHelpData(ref dt, txtFilter.Text);
            gvSRC.DataSource = dt;
        }
        private void btnFilter_Click(object sender, EventArgs e)
        {
            filter();
        }

        private void txtFilter_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                filter();
            }
        }
    }
}
